<template>
	<view>
		<view class="goods-item">
			<view class="left-view">
				<radio v-if="showRadio" :checked="item.goods_state" color="#C00000" @click="radioClick"></radio>
				<image class="goods-image" :src="item.goods_small_logo || defaultPic" ></image>
			</view>
			<view class="right-view">
				<view class="goods-name">{{item.goods_name}}</view>
				<view class="bottom-view">
					<view class="goods-price">￥{{item.goods_price | tofixed}}</view>
					<uni-number-box v-if="showNum" :min="1" :value="item.goods_count" @change="numberChange"></uni-number-box>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		props: {
			item:{
				type:Object,
				default:{	
				}
			},
			showRadio:{
				type: Boolean,
				//默认不展示radio组件
				default: false
			},
			showNum:{
				type: Boolean,
				//默认不展示numberBox组件
				default: false
			}
		},
		filters:{
			tofixed(num) {
				return Number(num).toFixed(2)
			}
		},
		data() {
			return {
				//默认空图片
				defaultPic:'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		methods:{
			//这是radio组件的事件处理函数
			radioClick(){
				this.$emit('radioChange',{goods_id:this.item.goods_id,goods_state:!this.item.goods_state})
			},
			numberChange(val){
				this.$emit('numChange',{goods_id:this.item.goods_id,goods_count:+val})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item{
		padding: 10px;
		border-bottom: 1px solid #efefef;
		display: flex;
		width: 750rpx;
		box-sizing: border-box;
		.left-view{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.goods-image{
				width: 100px;
				height: 100px;
				display: block;
			}
		}
		.right-view{
			margin-left: 10px;
			display: flex;
			flex: 1;
			flex-direction: column;
			justify-content: space-between;
			.goods-name{
				font-size: 15px;
			}
			.bottom-view{
				// margin-top: 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.goods-price{
					color: #C00000;
					font-size: 16px;
					
				}
			}
		}
	}
</style>
